#include <iostream>
using namespace std;
#define STACK_SIZE 100
typedef struct  bitNode{
    char data;
    bitNode *lchild;
    bitNode *rchild;
}bitNode,*bitTree;

typedef struct  biNode1{
    bitNode* bt;
    int tag;
}bitNode1,*bitTree1;


class Stack{
private:
    bitNode1  ** base;
    bitNode1  ** top;
    int stacklength;
public:
    Stack(){ base = top = new bitTree1[STACK_SIZE];
        stacklength = STACK_SIZE;
    }
    void push(bitNode1 *t){
        *top++ = t;
    }
    void pop(bitNode1 *&t){
        t = *--top;
    }
    bool isEmpty(){
        return base==top?true:false;
    }
};


class Tree{
private:
    bitNode * head;
    void creat(bitNode *&t){
        char data;
        cin>>data;
        if(data != '.') t = NULL;
        else{
            t = new bitNode;
            t -> data = data;
            creat(t->lchild);
            creat(t->rchild);
        }
    }
public:
    void inorderTree(){
        bitNode1* p
        = head;
        Stack s;
        while(p!=NULL || !s.isEmpty()){
            if(p != NULL){
                cout<<p->data;
                s.push(p);
                p = p->lchild;
            }
            else{
                s.pop(p);
                p = p- >rchild;
            }
        }
    }
    
    void middleOrderTree(){
        bitNode *p = head;
        Stack s;
        while( p || !s.isEmpty()){
            s.push(p);
            p = p->lchild;
        }
    }
};
